/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------

stmt_ptr parse_stmt(void)
{
	if (m_cursor->identity == TOK_OPEN_BRACE)
	{
		return parse_stmt_block();
	}
	
	expr_ptr expr = parse_expr();

	if (!expr)
	{
		return expr;
	}
	
	if (m_cursor->identity != TOK_SEMICOLON)
	{
		unexpected_token_error(TOK_SEMICOLON);
		m_cursor.advance();
		return stmt_ptr();
	}

	m_cursor.advance();
	
	return expr;
}

// ----------------------------------------------------------------------------

stmt_block_ptr parse_stmt_block(void)
{
	stmt_block_ptr block;

	if (m_cursor->identity != TOK_OPEN_BRACE)
	{
		unexpected_token_error(TOK_OPEN_BRACE);
		return block;
	}
	
	m_cursor.advance();
	
	block = boost::make_shared<stmt_block_type>();
	stmt_ptr stmt;
	
	while (m_cursor)
	{
		if (m_cursor->identity == TOK_CLOSE_BRACE)
		{
			m_cursor.advance();
			return block;
		}
		
		if ((stmt = parse_stmt()))
		{
			block->statements.push_back(stmt);
		}
		else
		{
			return block;
		}
	}

	return block;
}

// ----------------------------------------------------------------------------
